def orm_to_dict(obj):
    if obj is None:
        return None
    result = {}
    for column in class_mapper(obj.__class__).columns:
        result[column.name] = getattr(obj, column.name)
    return result
